package com.aizhixin.test.question.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;
import java.util.List;
import javax.swing.tree.TreePath;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;

import com.aizhixin.test.question.dto.AllAnswerRecordDTO;

@Component
public class AllAnswerRecordDAO {
@Autowired
private JdbcTemplate jdbcTemplate;

/**
 * 查看一个用户的答题汇总
 * SELECT  q.USER_ID,q.NOW_POINTS,q.TOTAL_ANSWER_NUMBERS,q.RIGHT_STEM_TOTAL_NUMBERS,q.ERROL_STEM_TOTAL_NUMBERS FROM answer_points_president_accounts as q WHERE q.USER_ID=2
 *ID
USER_ID
NOW_POINTS
RIGHT_STEM_TOTAL_NUMBERS
ERROL_STEM_TOTAL_NUMBERS
TOTAL_ANSWER_NUMBERS

 */
public List<AllAnswerRecordDTO>getuserEveryDayAnserImforMation(Long userId) {
	final String sql="SELECT  q.ID,q.USER_ID,q.NOW_POINTS,q.TOTAL_ANSWER_NUMBERS,q.RIGHT_STEM_TOTAL_NUMBERS,q.ERROL_STEM_TOTAL_NUMBERS FROM answer_points_president_accounts as q WHERE q.USER_ID=?";
	List<AllAnswerRecordDTO> list=jdbcTemplate.query(sql,
			new Object []{userId}, 
	new int[] {Types.INTEGER},
		new RowMapper<AllAnswerRecordDTO>() {
		public AllAnswerRecordDTO mapRow(ResultSet rs,
				int rowNum)
			throws SQLException{
			AllAnswerRecordDTO test =new AllAnswerRecordDTO();
			test.setUserId(rs.getLong("USER_ID"));
			test.setNowPiont(rs.getLong("NOW_POINTS"));
			test.setAnswerAllNumber(rs.getLong("TOTAL_ANSWER_NUMBERS"));
			test.setRightAnwserTotal(rs.getLong("RIGHT_STEM_TOTAL_NUMBERS"));
			test.setErrolAnswerTotal(rs.getLong("ERROL_STEM_TOTAL_NUMBERS"));
			test.setId(rs.getLong("ID"));
			return test;
			}
		});
	if (null != list && list.size() > 0) {
		return list;
	}else {
		return null;
	}
}

}
